<?php

class Default_IndexController extends Zend_Controller_Action
{

    public function init()
    {
        $this->view->homemenu = 'id="current"';
    }

    public function indexAction()
    {
        $page = $this->_getParam('page');
        $page = (isset($page)) ? $page : 1;

        if (!Nosql_Util_Validator::validateInt($page)) {
            throw new Exception('Valor invalido en los parametros');
        }

        $this->view->title = ' Inicio - Pagina ' . $page;


        //get all the posts
        $postModel = new Nosql_Model_Mysql_Post();

        $posts = $postModel->listPosts($page);

        $this->view->posts = $posts['items'];
        if (!isset($this->view->posts)  || count($this->view->posts) == 0) {
            $this->view->error = 'No se encontraron artículos';
        } else {
            $this->view->paginator = $posts['paginator'];
            $this->view->urlPagination = '/index/index/';
        }

    }


}

